package com.zjzywl.smoke.task;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zjzywl.smoke.repository.AlarmRepository;
import com.zjzywl.smoke.entity.Device;


@Component
public class FocusLocation implements Runnable {
	
	@Autowired
	private AlarmRepository alarmRepository;
	
	
	@Override
	public void run() {	

		handle();
	}
	
	public void handle() {
		//调用sql语句，统计一周内每个设备的报警数量
		Date bTime = new Date();
		Date eTime = new Date();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		String bStr = format.format(bTime.getTime()-6*86400*1000);
		String eStr = format.format(eTime);
		
		List alarms =  alarmRepository.getDeviceAlarmCountByTime(bStr,eStr,5);
		
		//当报警数量超过设定值，加入重点关注位置
		for (Object object : alarms) {
			Device obj = (Device)(((Object[])object)[0]);
			Long count = (Long)(((Object[])object)[1]);
			
			System.out.println(obj.getAddress());
			System.out.println(count);
		}		
	}

}
